package main

import "fmt"

type animal interface {
	move()
	eat(string)
}
type cat struct {
	name string
	feet int8
}

func (c cat) move() {
	fmt.Println("走猫步")
}
func (c cat) eat(s string) {
	fmt.Printf("猫吃%s\n", s)
}

type chicken struct {
	feet int8
}

func (c chicken) move() {
	fmt.Println("鸡冻")
}
func (c chicken) eat(s string) {
	fmt.Printf("鸡吃%s\n", s)
}

func main() {
	var a1 animal
	fmt.Printf("%T\n", a1) // <nil>
	c := cat{
		"孬蛋",
		3,
	}
	// cat 实现了完整的animal的方法,所以可以这样写
	a1 = c
	a1.eat("小精豆")
	fmt.Printf("%T\n", a1) // main.cat
	fmt.Println(a1)        // {孬蛋 3}

	k := chicken{
		feet: 2,
	}
	a1 = k
	fmt.Printf("%T\n", a1) // main.chicken
}
